package com.mariusz.ui.models;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.mariusz.data.dto.Property;

public class PropertiesTableModel extends AbstractTableModel {
	private static final String[] PROPERTIES_TABLE_HEADER = new String[] {
		"Property Name","Address", "Rooms count" };
	private List<Property> properties;
	
	public PropertiesTableModel(List<Property> properties){
		this.properties = properties;
	}
	
	@Override
	public int getColumnCount() {
		return PROPERTIES_TABLE_HEADER.length;
	}

	public String getColumnName(int i) {
		return PROPERTIES_TABLE_HEADER[i];
	}

	@Override
	public int getRowCount() {
		if (properties != null) {
			return properties.size();
		} else {
			return 0;
		}
	}

	public Class getColumnClass(int c) {
		if(properties.size() > 0){
			return getValueAt(0, c).getClass();
		}else{
			//return default
			return String.class;
		}
	}

	public boolean isCellEditable(int row, int col) {
		return false;
	}

	public void setValueAt(Object value, int row, int col) {
		return;
	}

	@Override
	public Object getValueAt(int row, int col) {
		switch (col) {
		case 0: 
			return properties.get(row).getName();
		case 1:
			return properties.get(row).getAddress();
		case 2:
			return properties.get(row).getRooms().size();
		}
		return null;
	}

}
